package com.primeton.sftp;
import com.jcraft.jsch.*;
import com.primeton.sftp.util.SFTPUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import sun.misc.BASE64Decoder;

import java.io.*;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class testJV {
    public static void main(String[] args) throws IOException, JSchException, SftpException {
//        JSch jsch = new JSch();
//        Session session = jsch.getSession("root","192.168.1.128",22);
//        session.setPassword("root");
//        session.connect();
////        String command = "scp -f /tmp/123.txt";
////        Channel channel = session.openChannel("exec");
////        ((ChannelExec)channel).setCommand(command);
////        OutputStream out=channel.getOutputStream();
////        channel.connect()
//        ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
//        InputStream stream = sftp.get("/tmp/123.txt");
//        BufferedReader br = new BufferedReader(new InputStreamReader(stream));
//        br.readLine();
//        SFTPUtil sftp = new SFTPUtil("root", "root", "192.168.1.128", 22);

//        sftp.login(); //sftp登入
//        sftp.getN();
//        sftp.logout();
//        SimpleDateFormat mf = new SimpleDateFormat("yyyy-MM-dd");
////        SimpleDateFormat mf = new SimpleDateFormat("yyyy-MM-05 00:00:00");
//        Date date = new Date();
//        Date currentDate = new Date();
//        Calendar calendar = Calendar.getInstance();
//        Calendar currentCalendar = Calendar.getInstance();
//        calendar.setTime(date);
////        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
////        calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-1); // 前一天日期
//        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH));
//        date = calendar.getTime();
//        currentDate = currentCalendar.getTime();
//        String currentDay = mf.format(currentDate);
//        String accDate = mf.format(date);
//        String s = accDate.split(" ")[0];
//
//        System.out.println(s.split("-")[2]);
//        System.out.println(accDate);
//        System.out.println(currentDay);
        String path = "D_006_F10004_006_68903_";
        String filePath = "/app/FModel/month/M_006_F10004_006_68903_";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Date date = new Date();
        String s = df.format(date);// new Date()为获取当前系统时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-1);
        date = calendar.getTime();
        String accDate = df.format(date);
        System.out.println(accDate);
        String s1 = accDate.split(" ")[0];

        String chkFilePath = filePath+s1.replaceAll("-","")+"_00.chk";
        filePath = filePath+s1.replaceAll("-","")+"_00.txt";
        String chkPath = path+s1.replaceAll("-","")+"_00.chk";
        path = path+s1.replaceAll("-","")+"_00.txt";
        System.out.println(chkFilePath);
        System.out.println(filePath);
        System.out.println(path);
        System.out.println(chkPath);
//        String firstSql = "select count(1) as sum,log_type from WFP_INTERFACE_LOG";
//        String sql = firstSql + " where creation_date<to_date('" +currentDay + "','yyyy-mm-dd hh24:mi:ss') and creation_date>to_date('" + accDate + "','yyyy-mm-dd hh24:mi:ss') group by log_type";
//        System.out.println(sql);
//        final BASE64Decoder decoder = new BASE64Decoder();
//        String sftpPassword = "YlhPNk5aM2xUMU5O";
//        String password = null;
//        try {
//            password = new String(decoder.decodeBuffer(sftpPassword), "UTF-8");
//        } catch (IOException e) {
////            logger.error(e.toString());
//        }
//        System.out.println("密码(后续删除):"+password);

    }
}

